package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.converter.StringToBaseEnumConverterFactory;
import com.atguigu.lease.web.admin.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author kk
 * #date 2024/6/18 21:19
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {


    @Autowired
    StringToBaseEnumConverterFactory converterFactory;
    @Autowired
    AuthenticationInterceptor authenticationInterceptor;

    //类型转换器
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(converterFactory);
    }

    //注册拦截器


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor)
                .addPathPatterns("/admin/**").excludePathPatterns("/admin/login/**");
    }
}
